<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="file">
  <hr>
  <img src="" alt="">

  <script>
    document.querySelector('input').addEventListener('change', function () {
      if (this.files.length > 0) {
        let fileObj = this.files[0] 
        let url = URL.createObjectURL(fileObj)
        console.log(url)
        document.querySelector('img').src = url
      } else {
      }
    })
  </script>
</body>

</html>